/**
 * Created by bianlian on 2018/4/19.
 */
const qiniu = require('qiniu');

let accessKey= 'X0VFw3_JRawgDXKZc4aXZbePiv5RWbiEjYZEEby0';
let secretKey= 'ub8sMeK9E1H_niLmyd1Ry-9TeiLyTf4wPv6M9dBY';

var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

var options = {
    scope: 'argency',
    // callbackUrl: 'http://localhost:9003/upload/callback',
    callbackBody: '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}',
    callbackBodyType: 'application/x-www-form-urlencoded'
}
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken=putPolicy.uploadToken(mac);

console.log(uploadToken);

// exports.callback = async(ctx) => {
//     ctx.body = {
//         result: 200,
//         data: ctx,
//         message: "succses"
//     };
// }

exports.uploadToken = async(ctx) => {
    console.log(uploadToken);
    ctx.body = {
        result: 200,
        uploadToken,
        message: "success"
    };
}

